package org.video.mine.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import org.video.mine.R;
import org.video.mine.databinding.HomeTitleBinding;
import org.video.mine.databinding.MovieInfoBinding;
import org.video.mine.entity.HomeTitleEntity;
import org.video.mine.entity.MovieInfoEntity;

import java.util.List;

public class MovieItemInfoAdapter extends RecyclerView.Adapter<MovieItemInfoAdapter.ViewHolder> {

    List<MovieInfoEntity> titleEntities;
    Context context;

    public MovieItemInfoAdapter(List<MovieInfoEntity> titleEntities, Context context) {
        this.titleEntities = titleEntities;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        MovieInfoBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.movie_info,parent,false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        MovieInfoEntity titleEntity = titleEntities.get(position);
        Log.d("title===",titleEntity.getName());
        holder.getTitleBinding().setMovieInfo(titleEntity);
    }

    @Override
    public int getItemCount() {
        return titleEntities.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        MovieInfoBinding titleBinding = null;

        public ViewHolder(MovieInfoBinding titleBinding) {
            super(titleBinding.getRoot());
            this.titleBinding = titleBinding;
        }

        public MovieInfoBinding getTitleBinding(){
            return titleBinding;
        }
    }
}
